package com.cicc.beergamevirtualsimulationsystem.controller;

import com.cicc.beergamevirtualsimulationsystem.common.constant.EchartsConstant;
import com.cicc.beergamevirtualsimulationsystem.model.R;
import com.cicc.beergamevirtualsimulationsystem.model.echarts.vo.EchartsVo;
import com.cicc.beergamevirtualsimulationsystem.model.echarts.dto.EchartsDto;
import com.cicc.beergamevirtualsimulationsystem.service.EchartsService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName EchartsController
 * @Description TODO
 * @Date 2024/11/6 14:12
 * @Version 1.0
 */


@RestController
@RequestMapping("/api/echarts")
public class EchartsController {

    @Autowired
    private EchartsService echartsService;

    @GetMapping("/Chart")
    public R<EchartsVo> chartDisplay(@Valid EchartsDto echartsDto) {
        // 根据 chartType 来决定调用哪个方法
        if ("barchart".equalsIgnoreCase(echartsDto.getChartType())) {
            return R.ok(echartsService.queryGameResult(echartsDto.getRoomId(), echartsDto.getUserRole()));
        } else if ("linechart".equalsIgnoreCase(echartsDto.getChartType())) {
            return R.ok(echartsService.queryGameResultByRoomId(echartsDto.getRoomId(), echartsDto.getUserRole()));
        } else if ("fullProfits".equalsIgnoreCase(echartsDto.getChartType())) {
            return R.ok(echartsService.queryAllPlayerProfit(echartsDto.getRoomId(),echartsDto.getUserRole()));

        } else {
            return R.failed(EchartsConstant.CHART_TYPE_ERROR);
        }
    }


    /**
     * 游戏玩家局中数据展示
     **/
    @GetMapping("/playerData")
        public R<EchartsVo> playerData(@Valid EchartsDto echartsDto) {
            return R.ok(echartsService.queryPlayerData(echartsDto.getRoomId(), echartsDto.getPeriod(), echartsDto.getUserRole()));
        }

    /**
     * 主持人局中数据展示
     */
    @GetMapping("/hostData")
    public R<EchartsVo> hostData(@Valid EchartsDto echartsDto) {
        return R.ok(echartsService.queryPlayerDataByRoomId(echartsDto.getRoomId(), echartsDto.getPeriod()));
    }

    /**
     * 游戏玩家供给数据展示
     **/
    @GetMapping("/playerSupplyData")
    public R<EchartsVo> playerSupplyData(@Valid EchartsDto echartsDto) {
        return R.ok(echartsService.queryPlayerSupplyData(echartsDto.getRoomId(), echartsDto.getPeriod(), echartsDto.getUserRole()));
    }

}
